package com.medical.data.utils;

import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result {

    @ApiModelProperty("是否成功")
    private Boolean success;
    @ApiModelProperty("返回码")
    private Integer code;
    @ApiModelProperty("返回消息")
    private String message;
    @ApiModelProperty("返回数据")
    Map<String,Object> data = new HashMap<>();
    @ApiModelProperty("上传图片返回值,0是正确1是错误")
    private Integer errno;

    private Result(){}

    @ApiOperation("成功")
    public static Result ok(){
        Result r = new Result();
        r.setCode(ResultCode.SUCCESS.getCode());
        r.setSuccess(true);
        r.setMessage(ResultCode.SUCCESS.getDesc());
        return r;
    }
    @ApiOperation("失败")
    public static Result error(){
        Result r = new Result();
        r.setCode(ResultCode.ERROR.getCode());
        r.setSuccess(false);
        r.setMessage(ResultCode.ERROR.getDesc());
        return r;
    }
    @ApiOperation("设置消息")
    public Result message(String message){
        this.setMessage(message);
        return this;
    }
    @ApiOperation("设置返回码")
    public Result code(Integer code){
        this.setCode(code);
        return this;
    }
    @ApiOperation("设置成功")
    public Result success(Boolean success){
        this.setSuccess(success);
        return this;
    }
    @ApiOperation("设置返回数据")
    public Result data(String key, Object value){
        this.data.put(key,value);
        return this;
    }
    @ApiOperation("设置返回数据")
    public Result data(Map<String,Object> map){
        this.setData(map);
        return this;
    }
    //    @ApiOperation("用于加密数据的返回")
//    public R data(){
//        this.data.put(key,value);
//        return this;
//    }
    @ApiOperation("设置图片上传状态码")
    public Result errno(Integer errno){
        this.setErrno(errno);
        return this;
    }
}
